package com.yun.platform.es.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Date;

/**
 * 但这个并不是作为时序数据库使用，时序数据库使用 index需要自动生成同时加上时间索引。
 * 所以我们需要用客户端操作入库，ElasticsearchConfig
 * esService.save(entity, MYINDEX) ? "SUCCESS" : "FAIL";
 */
@Data
@Document(indexName = "demo", shards = 1, replicas = 1)
public class Demo {

    @Id
    private int id;

    @Field(type = FieldType.Text)
    private String pid;

    @Field(type = FieldType.Text)
    private String name;

    //序列号，用于给外部展示的id
    @Field(type = FieldType.Keyword)
    private String serialNum;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
    @Field(type= FieldType.Date, format= DateFormat.custom, pattern="yyyy-MM-dd HH:mm:ss.SSS")
    private Date createTime;

    @Override
    public String toString() {
        return "Product [id=" + id + ", name=" + name + "]";
    }

}
